package regexp.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author DCSGO
 * @version 1.0
 * 显示正则表达式结果
 */
public class RegExpFind {
    public static void printFind(String content, String regStr, int mode) {
        Pattern pattern = Pattern.compile(regStr, mode);
        Matcher matcher = pattern.matcher(content);
        System.out.println(regStr + "匹配到：");
        while (matcher.find()) {
            System.out.print(matcher.group(0) + " ");
        }
        System.out.println();
    }

    public static void printFind(String content, String regStr) {
        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        System.out.println(regStr + "匹配到：");
        while (matcher.find()) {
            System.out.print(matcher.group(0) + " ");
        }
        System.out.println();
    }

    public static void printFindGroups(String content, String regStr, int groups) {
        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        System.out.println(content + " 通过 " + regStr + "匹配到：");
        int cnt = 0;
        while (matcher.find()) {
            System.out.println("找到 " + (++cnt));
            for (int i = 0; i <= groups; i++) {
                System.out.print(matcher.group(i) + " ");
            }
            System.out.println();
        }

    }
}
